package com.hxlc.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hxlc.dao.EquipmentInfoDao;
import com.hxlc.dao.EquipmentInfoDetailsDao;
import com.hxlc.enums.EquipmentEnum;
import com.hxlc.model.QueryResp;
import com.hxlc.pojo.EquipmentInfoDetailsEntity;
import com.hxlc.pojo.EquipmentInfoEntity;
import com.hxlc.service.StatuService;
import com.hxlc.service.handler.EquipmentHandler;
import com.hxlc.util.RectField;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class StatuServiceImpl implements StatuService {

    @Autowired
    EquipmentInfoDao equipmentInfoDao;
    @Autowired
    EquipmentInfoDetailsDao equipmentInfoDetailsDao;

    @Autowired
    EquipmentHandler equipmentHandler;

    @Override
    public List<QueryResp> getServerStatu(String module) {
        List<EquipmentInfoEntity> equipmentInfoEntities = equipmentInfoDao.getEquipmentInfoByModuleAndType(module, EquipmentEnum.SERVER.getType());
        List<String> ids = RectField.getBeanFields(equipmentInfoEntities, "id");
        List<EquipmentInfoDetailsEntity> equipmentInfoDetailsList = equipmentInfoDetailsDao.getByEquipmentInfoIds(ids);
        log.info("ids:{}", JSONObject.toJSONString(equipmentInfoDetailsList));
        return equipmentHandler.getQeryRespsByEquipmentInfos(equipmentInfoEntities,equipmentInfoDetailsList);
    }

}
